<template>
  <el-dialog title="选择账户"
             :visible.sync="dialogForm"
             width="1200px"
             append-to-body>
    <base-list ref="selectAccountForm"
               :condition="condition"
               :datas.sync="accountGroupData"
               :pageSearch="pageSearch">
      <el-form :inline="true"
               :model="condition"
               class="search-form"
               slot="search"
               label-width="100px">
        <el-row>
          <el-col :span="7">
            <el-form-item label="助记码">
              <auto-search-resource searchType="JOB_RY"
                                    searchName="mnemonicCode"
                                    @selectName="v=>condition['search_LIKE_mnemonicCode']=v"></auto-search-resource>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="账户名称">
              <auto-search-resource searchType="JOB_RY"
                                    searchName="name"
                                    @selectName="v=>condition['search_LIKE_name']=v"></auto-search-resource>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="所属客户">
              <auto-search-resource searchType="JOB_RY"
                                    searchName="orgName"
                                    @selectName="v=>condition['search_LIKE_orgName']=v"></auto-search-resource>
            </el-form-item>
          </el-col>
          <el-col :span="1">
            <el-button plain
                       type="primary"
                       icon="el-icon-search"
                       @click="loadData">查询</el-button>
          </el-col>
        </el-row>
      </el-form>
      <el-table slot="list"
                :data="accountGroupData"
                border
                stripe
                max-height="500"
                @selection-change="handleSelectionChange">
        <el-table-column type="selection"
                         width="50"></el-table-column>
        <el-table-column label="序号"
                         type="index"
                         width="50"></el-table-column>
        <el-table-column prop="mnemonicCode"
                         label="助记码"
                         
                         min-width="120"></el-table-column>
        <el-table-column prop="name"
                         label="账户名称"
                         
                         min-width="120"></el-table-column>
        <el-table-column prop="orgName"
                         label="客户名称"
                         
                         min-width="120"></el-table-column>
      </el-table>
    </base-list>
    <div style="text-align:center">
      <el-button plain
                 type="primary"
                 @click="selectAccount">确定</el-button>
      <el-button plain
                 type="info"
                 @click="dialogForm = false">返回</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getAccountList } from '@/api/commerce/account'
import autoSearchOrg from '@/components/autocomplete/autoSearchOrg'
import autoSearchResource from '@/components/autocomplete/autoSearchResource'

export default {
  name: 'addAccountForm',
  components: {
    autoSearchOrg,
    autoSearchResource
  },
  data() {
    return {
      condition: {'search_ISNULL_group.id':'1'}, // 查询条件
      accountGroupData: [], // table数组
      pageSearch: getAccountList, // 分页查询api接口
      id: '',
      dialogForm: false,
      multipleSelection: []
    }
  },
  methods: {
    loadData() {
      this.$refs.selectAccountForm.loadData()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
      console.log(val)
    },
    handleDialogFormOpen(bool, item) {
      if (bool) {
        let form = JSON.parse(JSON.stringify(item))
        this.$refs.selectAccountForm.form = {
          id: form.id,
          name: form.name,
          orgName: form.orgName,
          orgId: form.orgId
        }
        this.$refs.selectAccountForm.isEdit = true
        this.$refs.selectAccountForm.dialogForm = true
      } else {
        this.$refs.selectAccountForm.dialogForm = true
      }
    },
    // 选择账户
    selectAccount(){
      this.$emit('load',this.multipleSelection)
      this.dialogForm = false
    }
  }
}
</script>

<style scoped>
</style>
